package epfc.tfe.ts.domain;

import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Version;
import javax.jdo.annotations.VersionStrategy;

/**
 * Abstract class used as a base for domain objects
 * @author propater
 *
 */

// this class is created to constrain the generic type used in 
// GenericDao and be able to call common/technical fields when manipulating it
// (typically calling getId() to retrieve an attached copy or using versionning)
@PersistenceCapable

//this will copy the fields of the superclass into each of its subclasses
@Inheritance(strategy=InheritanceStrategy.SUBCLASS_TABLE) 
@Version(
		strategy=VersionStrategy.VERSION_NUMBER,
		extensions={@Extension(vendorName="datanucleus", key="field-name", value="version")}
		)
// we introduce here a hard dependency on Google's datastore. 
// Unfortunately, it seems this is inevitable if we use JDO and bind the version to an explicit field.
public abstract class AbstractDomainObject implements DomainObject {
	
	@PrimaryKey  
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	protected Long id;
	@Persistent
	protected Date lastUpdated;
	@Persistent
	protected Date created;
	@Persistent
	protected Long version;
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Date getLastUpdated() {
		return lastUpdated;
	}
	public void setLastUpdated(Date lastUpdated) {
		this.lastUpdated = lastUpdated;
	}
	public Date getCreated() {
		return created;
	}
	public void setCreated(Date created) {
		this.created = created;
	}
	public Long getVersion() {
		return version;
	}
	public void setVersion(Long version) {
		this.version = version;
	}
	
	

}
